home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_12_11
/
allison
/
exhaust1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-05
|
600b
|
37 lines
LISTING 17 - Illustrates set_new_handler
// exhaust1.cpp
#include <iostream.h>
#include <stdlib.h>
#include <new.h>
inline void my_handler()
{
cout << "Memory exhausted" << endl;
abort();
}
main()
{
set_new_handler(my_handler);
for (int i = 0; ; ++i)
{
(void) new double[100];
if ((i+1)%10 == 0)
cout << (i+1) << " allocations" << endl;
}
}
/* Output:
10 allocations
20 allocations
30 allocations
40 allocations
50 allocations
60 allocations
70 allocations
Memory exhausted
Abnormal program termination
*/